home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Champak 109
/
Vol 109.iso
/
games
/
bubble_t.swf
/
scripts
/
frame_1
/
DoAction_2.as
next >
Wrap
Text File
|
2008-11-12
|
18KB
|
567 lines
function pressedMouse()
{
if(gUseKeyboard.val)
{
return undefined;
}
fireProjectile();
}
function fireProjectile()
{
if(gMode != cNORMAL)
{
return undefined;
}
if(gNewBubbleMode == cMOVE)
{
return undefined;
}
_root.machine_main.gotoAndPlay("pump");
gFireSound.attachSound("fire_sound");
gFireSound.start();
var a = _root.gun.barrel.pAngle;
if(a == -1.5707963267948966)
{
a += 0.00001;
}
_root.projectile._x = _root.gun._x + gGunLength * Math.cos(a);
_root.projectile._y = _root.gun._y + gGunLength * Math.sin(a);
gBounceBack = false;
gTarget = getTarget(a);
_root.projectile.bubble.gotoAndStop(gCurrentType);
_root.projectile.bubble.graphic.bonus.gotoAndStop(gCurrentBonus);
gMode = cFIRE;
gFrameTimer = getTimer();
_root.new_bubble.bubble.gotoAndStop(gNextType);
_root.new_bubble.bubble.graphic.bonus.gotoAndStop(gNextBonus);
_root.new_bubble._x = gNewBubbleStartX;
_root.new_bubble._y = gNewBubbleStartY;
gNewBubbleMode = cMOVE;
_root.future_bubble.bubble.gotoAndStop(gFutureType);
_root.future_bubble.bubble.graphic.bonus.gotoAndStop(gFutureBonus);
_root.future_bubble.gotoAndPlay("animate");
}
function getTarget(vAngle)
{
gProjectileAngle = vAngle;
var lProjectileLoc = {x:_root.projectile._x,y:_root.projectile._y};
gTilt = -1.5707963267948966 - vAngle;
gTilt = normalizeAngle(gTilt);
var lOriginRot = rotate(gOrigin,lProjectileLoc,gTilt);
var ri0 = {x:gRdX,y:gRdY};
var ri1 = rotate(ri0,{x:0,y:0},gTilt);
var ci0 = {x:gCdX,y:gCdY};
var ci1 = rotate(ci0,{x:0,y:0},gTilt);
gTarget = 0;
var lClosestDestY = -1000;
gSquashDist = 0;
var i = gNumRows - 1;
while(i >= 0)
{
if(gBubbleRow[i].length >= 1)
{
var lRowOrigin = {x:lOriginRot.x + i * ri1.x,y:lOriginRot.y + i * ri1.y};
if(ci1.x < 0)
{
var lSign = -1;
}
else
{
var lSign = 1;
}
var lFirstCol = Math.ceil((lProjectileLoc.x - lSign * gSpacing - lRowOrigin.x) / ci1.x);
var lLastCol = Math.floor((lProjectileLoc.x + lSign * gSpacing - lRowOrigin.x) / ci1.x);
var j = lFirstCol;
while(lLastCol >= j)
{
if(j >= 0)
{
var b = getBubbleAt(i,j);
if(b != 0 && b != -1)
{
var lTargetX = lRowOrigin.x + j * ci1.x;
var lTargetY = lRowOrigin.y + j * ci1.y;
var dx = lProjectileLoc.x - lTargetX;
var lMinDist = gSpacing / 2 + gMinSpacing;
if(dx >= lMinDist)
{
var lSquashDist = 0;
}
else
{
var lSquashDist = Math.sqrt(lMinDist * lMinDist - dx * dx);
}
var lDestY = lTargetY + lSquashDist;
if(lClosestDestY < lDestY)
{
lClosestDestY = lDestY;
gTarget = b;
gSquashDist = lSquashDist;
gStartSquashDist = Math.sqrt(gSpacing * gSpacing - dx * dx);
gSquashThresholdDist = lProjectileLoc.y - lTargetY - gStartSquashDist;
}
}
}
j++;
}
}
i--;
}
if(gTarget)
{
gTravelDist = 0;
gThresholdDist = lProjectileLoc.y - lClosestDestY;
var xt1 = lProjectileLoc.x;
var yt1 = lClosestDestY;
gTangentPosition = rotate({x:xt1,y:yt1},lProjectileLoc,- gTilt);
var lTangentPos = pixelsToPos(gTarget._x + _root.bubble_MCA._x,gTarget._y + _root.bubble_MCA._y,gTangentPosition.x,gTangentPosition.y);
var lSnap = new Array();
var lStartPos = Math.ceil(lTangentPos);
var i = 0;
while(i < 5)
{
var cw = lStartPos + i;
if(5 < cw)
{
cw -= 6;
}
var lNeighborPos = getNeighborPos(gTarget,cw);
var lRow = lNeighborPos.r;
var lCol = lNeighborPos.c;
var lNeighbor = getBubbleAt(lRow,lCol);
if(lNeighbor == 0 && onStage(lRow,lCol))
{
lSnap.push(cw);
}
else if(lNeighbor != 0 && lNeighbor != -1)
{
break;
}
i++;
}
var lStartPos = Math.floor(lTangentPos);
var i = 0;
while(i < 5)
{
var ccw = lStartPos - i;
if(ccw < 0)
{
ccw += 6;
}
var lNeighborPos = getNeighborPos(gTarget,ccw);
var lRow = lNeighborPos.r;
var lCol = lNeighborPos.c;
var lNeighbor = getBubbleAt(lRow,lCol);
if(lNeighbor == 0 && onStage(lRow,lCol))
{
lSnap.push(ccw);
}
else if(lNeighbor != 0 && lNeighbor != -1)
{
break;
}
i++;
}
if(lSnap.length == 0)
{
return -1;
}
if(1 < lSnap.length)
{
lSnap = lSnap.sort(sortByPositionDist);
}
var p = lSnap[0];
gFinalPosition = getNeighborPos(gTarget,p);
var lTargetLoc = gridToPixels(gTarget.pRow,gTarget.pCol);
gSquashAngle = Math.atan2(lTargetLoc.y - gTangentPosition.y,lTargetLoc.x - gTangentPosition.x);
return gTarget;
}
return 0;
}
function normalizeAngle(vAngle)
{
while(vAngle < -3.141592653589793)
{
vAngle += 6.283185307179586;
}
while(3.141592653589793 < vAngle)
{
vAngle -= 6.283185307179586;
}
return vAngle;
}
function rotate(p, po, vAngle)
{
var x0 = p.x - po.x;
var y0 = p.y - po.y;
var x1 = x0 * Math.cos(vAngle) - y0 * Math.sin(vAngle);
var y1 = x0 * Math.sin(vAngle) + y0 * Math.cos(vAngle);
x1 += po.x;
y1 += po.y;
return {x:x1,y:y1};
}
function remapAngle(vAngle1, vAngle2)
{
vAngle1 -= vAngle2;
vAngle1 = normalizeAngle(vAngle1);
return vAngle1;
}
function moveProjectile(vTime)
{
if(gMode == cREMOVE)
{
if(0 < gGroup.length)
{
var b = gGroup.shift();
var r = b.pRow;
var c = b.pCol;
var lIndex = getOne(gBubbleList,b);
gBubbleList.splice(lIndex,1);
var lIndex = getOne(gBubbleRow[b.pRow],b);
gBubbleRow[b.pRow].splice(lIndex,1);
gBubbleCount[b.bubble._currentFrame]--;
var lBonus = b.bubble.graphic.bonus._currentFrame;
if(1 < lBonus)
{
b.swapDepths(gTopLevel++);
gBonus *= lBonus;
gBonusDelay = 5;
}
b.bubble.graphic.gotoAndPlay("pop");
gPopping++;
gBubble[r][c] = undefined;
gPopSound.attachSound("pop_sound");
gPopSound.start();
updateScore(gUnitScore);
gMatchScore += gUnitScore;
if(gUnitScore == 2)
{
gUnitScore = 3;
}
else if(gUnitScore == 3)
{
gUnitScore = 5;
}
else if(gUnitScore == 5)
{
gUnitScore = 10;
}
else
{
gUnitScore += 10;
}
if(gGroup.length == 0)
{
gPopDelay = 5;
gUnitScore = 20;
}
}
else if(0 < gStranded.length)
{
if(gPopDelay)
{
gPopDelay--;
return undefined;
}
var b = gStranded.shift();
var r = b.pRow;
var c = b.pCol;
var lIndex = getOne(gBubbleList,b);
gBubbleList.splice(lIndex,1);
var lIndex = getOne(gBubbleRow[b.pRow],b);
gBubbleRow[b.pRow].splice(lIndex,1);
gBubbleCount[b.bubble._currentFrame]--;
b.bubble.graphic.bonus.gotoAndStop(1);
b.bubble.graphic.gotoAndPlay("pop");
gPopping++;
gBubble[r][c] = undefined;
gPopSound.attachSound("pop_sound");
gPopSound.start();
updateScore(gUnitScore);
gMatchScore += gUnitScore;
gUnitScore += 10;
}
else if(!gPopping)
{
if(1 < gBonus || gBonusDelay)
{
if(gBonusDelay)
{
gBonusDelay--;
return undefined;
}
if(1 >= gBonus)
{
gBonusDelay = 0;
return undefined;
}
gBonusDelay = 5;
updateScore(gMatchScore * (gBonus - 1));
gBonus = 1;
gBonusSound.attachSound("bonus_sound");
gBonusSound.start(0,3);
}
else if(gBubbleList.length == 0)
{
levelOver();
}
else
{
gMode = cNORMAL;
}
}
return undefined;
}
if(gMode == cCONTACT)
{
var r = gFinalPosition.r;
var c = gFinalPosition.c;
finishProjectile(r,c);
return undefined;
}
var lDist = (vTime - gFrameTimer) * gProjectileSpeed / 1000;
if(gDebug)
{
lDist = 125 * gProjectileSpeed / 1000;
}
var x0 = _root.projectile._x;
var y0 = _root.projectile._y;
var x = x0 + lDist * Math.cos(gProjectileAngle);
var y = y0 + lDist * Math.sin(gProjectileAngle);
gTravelDist += lDist;
if(gTarget)
{
_root.projectile._xscale = 100;
_root.projectile._yscale = 100;
if(gTravelDist >= gThresholdDist)
{
gMode = cCONTACT;
_root.projectile._x = gTangentPosition.x;
_root.projectile._y = gTangentPosition.y;
_root.projectile._rotation = gSquashAngle * 180 / 3.141592653589793 - 90;
_root.projectile._yscale = (1 - gMaxSquash) * 100;
_root.projectile.bubble._rotation = (- gSquashAngle) * 180 / 3.141592653589793 + 90;
return undefined;
}
if(gSquashThresholdDist < gTravelDist)
{
var lObjDist = dist(x,y,gTarget._x + gOrigin.x,gTarget._y + gOrigin.y);
var lScale = 100 * (lObjDist - gSpacing / 2) / (gSpacing / 2);
_root.projectile._rotation = gSquashAngle * 180 / 3.141592653589793 - 90;
_root.projectile._yscale = - lScale;
_root.projectile.bubble._rotation = (- gSquashAngle) * 180 / 3.141592653589793 - 90;
_root.projectile.bubble.graphic.bonus._xscale = lScale;
_root.projectile.bubble.graphic.bonus._yscale = lScale;
}
}
else
{
if(_root.wall_bottom._y + gSpacing / 2 < y)
{
gCurrentType = gNextType;
gCurrentBonus = gNextBonus;
gNextType = gFutureType;
gNextBonus = gFutureBonus;
gFutureType = randomType();
gFutureBonus = chooseBonus();
if(gNewBubbleMode == cMOVE)
{
_root.projectile._y = -200;
gProjectileWaiting = true;
}
else
{
_root.projectile._x = _root.gun._x;
_root.projectile._y = _root.gun._y;
gProjectileWaiting = false;
}
_root.projectile.bubble.gotoAndStop(gCurrentType);
_root.projectile._xscale = 100;
_root.projectile._yscale = 100;
_root.projectile._rotation = 0;
_root.projectile.bubble._rotation = 0;
gAttachSound.attachSound("lost_bubble_sound");
gAttachSound.start();
gMode = cNORMAL;
updateScore(-10);
return undefined;
}
if(x < _root.wall_left._x + gMinSpacing)
{
var lScale = (_root.wall_left._x + gMinSpacing - x0) / (x - x0);
x = x0 + lDist * Math.cos(gProjectileAngle) * lScale;
y = y0 + lDist * Math.sin(gProjectileAngle) * lScale;
gOldProjectileAngle = gProjectileAngle;
gProjectileAngle = reflect(gProjectileAngle,1.5707963267948966);
_root.projectile._x = x;
_root.projectile._y = y;
_root.projectile._xscale = (1 - gMaxSquash) * 100;
gTarget = getTarget(gProjectileAngle);
if(gTarget == -1)
{
gProjectileAngle = normalizeAngle(gOldProjectileAngle + 3.141592653589793);
gTarget = 0;
}
gBounceSound.attachSound("bounce_sound");
gBounceSound.start();
}
else if(_root.wall_right._x - gMinSpacing < x)
{
var lScale = (_root.wall_right._x - gMinSpacing - x0) / (x - x0);
x = x0 + lDist * Math.cos(gProjectileAngle) * lScale;
y = y0 + lDist * Math.sin(gProjectileAngle) * lScale;
gOldProjectileAngle = gProjectileAngle;
gProjectileAngle = reflect(gProjectileAngle,1.5707963267948966);
_root.projectile._x = x;
_root.projectile._y = y;
_root.projectile._xscale = (1 - gMaxSquash) * 100;
gTarget = getTarget(gProjectileAngle);
if(gTarget == -1)
{
gProjectileAngle = normalizeAngle(gOldProjectileAngle + 3.141592653589793);
gTarget = 0;
}
gBounceSound.attachSound("bounce_sound");
gBounceSound.start();
}
else if(y < _root.ceiling._y + gMinSpacing)
{
var lScale = (_root.ceiling._y + gMinSpacing - y0) / (y - y0);
x = x0 + lDist * Math.cos(gProjectileAngle) * lScale;
y = y0 + lDist * Math.sin(gProjectileAngle) * lScale;
gOldProjectileAngle = gProjectileAngle;
gProjectileAngle = reflect(gProjectileAngle,0);
_root.projectile._x = x;
_root.projectile._y = y;
_root.projectile._yscale = (1 - gMaxSquash) * 100;
if(gSticky.val)
{
var lCol = (x - _root.bubble_MCA._x) / gSpacing;
var lClosestCol = Math.floor(lCol + 0.5);
var b = getBubbleAt(0,lClosestCol);
if(b == 0)
{
gMode = cCONTACT;
gFinalPosition = {r:0,c:lClosestCol};
return undefined;
}
if(lCol < lClosestCol)
{
var lNextCol = lClosestCol - 1;
}
else
{
var lNextCol = lClosestCol + 1;
}
var b = getBubbleAt(0,lNextCol);
if(b == 0)
{
gMode = cCONTACT;
gFinalPosition = {r:0,c:lNextCol};
return undefined;
}
gTarget = getTarget(gProjectileAngle);
if(gTarget == -1)
{
gProjectileAngle = normalizeAngle(gOldProjectileAngle + 3.141592653589793);
gTarget = getTarget(gProjectileAngle);
}
gBounceSound.attachSound("bounce_sound");
gBounceSound.start();
}
else
{
gTarget = getTarget(gProjectileAngle);
if(gTarget == -1)
{
gProjectileAngle = normalizeAngle(gOldProjectileAngle + 3.141592653589793);
gTarget = 0;
}
gBounceSound.attachSound("bounce_sound");
gBounceSound.start();
}
}
else if(x < _root.wall_left._x + gSpacing / 2)
{
var lScale = 100 * (x - _root.wall_left._x) * 2 / gSpacing;
_root.projectile._xscale = lScale;
}
else if(_root.wall_right._x - gSpacing / 2 < x)
{
var lScale = 100 * (_root.wall_right._x - x) * 2 / gSpacing;
_root.projectile._xscale = lScale;
}
else if(y < _root.ceiling._y + gSpacing / 2)
{
var lScale = 100 * (y - _root.ceiling._y) * 2 / gSpacing;
_root.projectile._yscale = lScale;
}
else
{
_root.projectile._xscale = 100;
_root.projectile._yscale = 100;
}
}
_root.projectile._x = x;
_root.projectile._y = y;
}
function finishProjectile(r, c)
{
var lName = "bubble" + r + "_" + c;
_root.bubble_MCA.attachMovie("bubble",lName,gBubbleLevel++);
var lBubble = _root.bubble_MCA[lName];
lBubble.pRow = r;
lBubble.pCol = c;
if(gDebug)
{
lBubble.bubble.position_display = "" + r + "," + c;
}
placeBubble(lBubble);
lBubble.bubble.gotoAndStop(gCurrentType);
gBubbleCount[gCurrentType]++;
lBubble.bubble.graphic.bonus.gotoAndStop(gCurrentBonus);
gBubble[r][c] = lBubble;
gBubbleList.push(lBubble);
gBubbleRow[r].push(lBubble);
gCurrentType = gNextType;
gCurrentBonus = gNextBonus;
gNextType = gFutureType;
gNextBonus = gFutureBonus;
gFutureType = randomType();
gFutureBonus = chooseBonus();
if(gDebug)
{
gNextType = 1;
}
_root.projectile.bubble.gotoAndStop(gCurrentType);
_root.projectile._xscale = 100;
_root.projectile._yscale = 100;
_root.projectile.bubble._yscale = 100;
_root.projectile._rotation = 0;
_root.projectile.bubble._rotation = 0;
_root.projectile.bubble.graphic.bonus._xscale = 100;
_root.projectile.bubble.graphic.bonus._yscale = 100;
if(gNewBubbleMode == cMOVE)
{
_root.projectile._y = -200;
gProjectileWaiting = true;
}
else
{
_root.projectile._x = _root.gun._x;
_root.projectile._y = _root.gun._y;
gProjectileWaiting = false;
}
gAttachSound.attachSound("attach_sound");
gAttachSound.start();
if(checkDie())
{
return undefined;
}
var lMatch = checkMatch(lBubble);
if(!lMatch)
{
lBubble.bubble.graphic.bonus.gotoAndStop(1);
}
}